<template>
  <div class="Add">
    <p>
      标题：
      <input type="text" v-model="title" />
    </p>
    <p>
      作者：
      <input type="text" v-model="author" />
    </p>
    <p>
      <button @click="add">添加</button>
    </p>
  </div>
</template>
<script>
export default {
  data() {
    return {
      title: "",
      author: ""
    };
  },
  methods: {
    add() {
      if (this.title == "" || this.author == "") {
        return alert("输入不合格");
      }
      var obj = { title: this.title, author: this.author };
      this.$emit("add", obj);
      this.title = this.author = "";
    }
  }
};
</script>